﻿@model XRM.Security.WebUI.Models.SystemUser.ADUserDialogFilterModel
@{
    ViewBag.Title = "Выбор пользователя";
    Layout = "~/Views/Shared/_LayoutDialog.cshtml";
}

<div class="modal-body">
    @using (Html.BeginForm("ADUsersDialog", "UserRegister", FormMethod.Post, new { id = "dlgADUsersDialogForm", @class = "form-horizontal form-horizontal-2" }))
    {      
        @Html.AntiForgeryToken()
        @Html.HiddenFor(m => m.UserDialogSubmitAction)
                
        <div class="form-group">
                @Html.LabelFor(m => m.LastNameFilter, new { @class = "control-label" })
                <div class="control-group">
                    <div class="col-sm-5">
                        <div class="input-group">
                            @Html.TextBoxFor(m => m.LastNameFilter, new { @class = "form-control" })
                            @Html.Partial("ClearButtonPartial")
                        </div>
                        @Html.ValidationMessageFor(m => m.LastNameFilter)
                    </div>
                </div>
        </div>
        <div class="form-group">
                @Html.LabelFor(m => m.FirstNameFilter, new { @class = "control-label" })
                <div class="control-group">
                    <div class="col-sm-5">
                        <div class="input-group">
                            @Html.TextBoxFor(m => m.FirstNameFilter, new { @class = "form-control" })
                            @Html.Partial("ClearButtonPartial")
                        </div>
                        @Html.ValidationMessageFor(m => m.FirstNameFilter)
                    </div>
                </div>
        </div>
        <div class="form-group">
            <div class="actions">
                <button class="btn btn-primary" type="submit" id="btnSearchADUsers">Поиск</button>
                <button class="btn btn-primary" type="submit" id="btnCreateUser">Создать пользователя</button>
            </div>
        </div>
    }    
                
    <div>
    @if (Model.UserDialogSubmitAction == "search")
    {
        Html.RenderAction("ADUsersGrid", "UserRegister", new { lname = Model.LastNameFilter, fname = Model.FirstNameFilter });
    }
    else if (Model.UserRegisterModel != null )
    {
        @Html.Partial("AddUserRegisterDialog2", Model.UserRegisterModel)
    }
    </div>
</div>

<script type="text/javascript" src="@(Url.Content("~/Scripts/AjaxRequest.js"))"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $(".input-group-btn .clearBtn").click(function () {
            $(this).parent().prev().val('');
        });

        $('#btnSearchADUsers').on('click', function () { SearchADUsers(); });
        $('#btnCreateUser').on('click', function () { CreateUser(); });
    });

    function SearchADUsers() {
        $('#UserDialogSubmitAction').val("search");
        return true;
    }
    function CreateUser() {
        $('#UserDialogSubmitAction').val("add");
        return true;
    }

    function CloseDialog() {
        $('#dlgADUsersDialog').modal('hide');
    }
</script>